#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
	int data;
	struct Node *next;
} Node;

typedef struct {
	Node *front;
	Node *rear;
} LinkQueue;

void initLinkQueue(LinkQueue *queue) {
	queue->front = queue->rear = NULL;
}

int isLinkQueueEmpty(LinkQueue *queue) {
	return queue->front == NULL;
}

void enqueueLinkQueue(LinkQueue *queue, int value) {
	Node *newNode = (Node *)malloc(sizeof(Node));
	newNode->data = value;
	newNode->next = NULL;
	if (isLinkQueueEmpty(queue)) {
		queue->front = queue->rear = newNode;
	} else {
		queue->rear->next = newNode;
		queue->rear = newNode;
	}
}

int dequeueLinkQueue(LinkQueue *queue) {
	if (isLinkQueueEmpty(queue)) {
		printf("Queue is empty. Cannot dequeue.\n");
		return -1;
	}
	Node *temp = queue->front;
	int value = temp->data;
	queue->front = queue->front->next;
	if (queue->front == NULL) {
		queue->rear = NULL;
	}
	free(temp);
	return value;
}

int peekLinkQueue(LinkQueue *queue) {
	if (isLinkQueueEmpty(queue)) {
		printf("Queue is empty. Cannot peek.\n");
		return -1;
	}
	return queue->front->data;
}

int main() {
	LinkQueue queue;
	initLinkQueue(&queue);

	enqueueLinkQueue(&queue, 10);
	enqueueLinkQueue(&queue, 20);
	enqueueLinkQueue(&queue, 30);

	printf("Dequeued value: %d\n", dequeueLinkQueue(&queue));
	printf("Front value: %d\n", peekLinkQueue(&queue));

	return 0;
}